$(document).ready(function() {	
	$('#startdate').datepicker({showButtonPanel: true});		
	$('#startdate').datepicker('option', {dateFormat: 'dd/mm/yy'},$.datepicker.regional['vi']);
	$('#enddate').datepicker({showButtonPanel: true});
	$('#enddate').datepicker('option', {dateFormat: 'dd/mm/yy'},$.datepicker.regional['vi']);
	$("#ui-datepicker-div").css("z-index", "1003" );
	$('#ui-datepicker-div').css('clip', 'auto');  
	$("#se_cate").multiSelect({ 
		selectAllText: 'Tất cả',
		noneSelected: 'Tất cả',
		oneOrMoreSelected: 'Bạn đã chọn % chuyên mục'						
	});	
	$.cookie('AUTOLOAD_NEWS', 1);
	$(window).scroll(function(){			
		if  ($(window).scrollTop() == $(document).height() - $(window).height()){
			loadNews();
		}
	}); 
});

function loadNews() {	
	var intPage 	= $('#ppage').val();	
	var strKeyword	= $('#keyword').val();	
	var intFi		= $('#filter').val();
	var strStart	= $('#startdate').val();	
	var strEnd		= $('#enddate').val();
	if($.cookie('AUTOLOAD_NEWS') == 1 && intPage > 0) {		
		$.cookie('AUTOLOAD_NEWS',0);	
		$('.boxNews .loading').show();
		var arrCate  = new Array();
		$('input[name="se_cate[]"]:checked').each(function(){
			 arrCate.push(this.value);
		});
		$.getJSON(				
			HOST_VFRIEND + 'ajax/news?act=6&page='+intPage+'&filter='+intFi+'&startdate='+strStart+'&enddate='+strEnd+'&keyword='+encodeURIComponent(strKeyword)+'&se_cate='+arrCate+'&callback=?',		
			function(response) {	
				var msg 	= response['msg'];
				var error	= response['error'];
				if(error == 0) {
					$('#ppage').remove();
					$('.boxNews .loading').remove();					
					$('.boxNews ul').append(response['dnews']);
				} else {
					alert(msg);
				}
				$.cookie('AUTOLOAD_NEWS', 1);
			}
		);
	}
}
actionSearch = function() {
	var strKeyword 	= $.trim($('#keyword').val());
	var intFilter	= $('#filter').val();
	var intCate		= $('input[name="se_cate[]"]:checked').length;
	var strStart	= $('#startdate').val();
	var strEnd 		= $('#enddate').val();
	if(strKeyword == '' && intFilter==0 && intCate==0 && strStart=='' && strEnd=='') {
		alert(name_required);
		$('#keyword').focus();
		return false;
	} else if(strKeyword != '' && strKeyword.length < 3) {
		alert(name_minlength);
		$('#keyword').focus();
		return false;
	}
	return true;
}